package org.icress.fusion.b2b

import org.icress.fusion.shiro.User
import org.apache.shiro.SecurityUtils

import org.springframework.transaction.annotation.*

class ProductService {

    static transactional = true
    
    @Transactional(readOnly = true)
    def list(params) {
        return Product.list(params)
    }
    
    @Transactional(readOnly = true)
    def show(id) {
        return Product.get(id)
    }
    
    def edit(id) {
        return Product.get(id)
    }

    def save(productInstance) {
        //get user
        def currentUser = User.findByUsername( SecurityUtils.getSubject().getPrincipal() )
        
        
        //validate
        productInstance.validate()
        
        //save
        productInstance.save(flush: true)

    }
    
    def update(productInstance) {
        //get user
        def currentUser = User.findByUsername(SecurityUtils.getSubject().getPrincipal())
        
        //set instance params
        productInstance.lastUpdated = new java.util.Date()
        
        //validate
        productInstance.validate()
        
        //save
        productInstance.save(flush: true)
    }
}
